package com.echoesnet.echoesshortvideo.Activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.echoesnet.echoesshortvideo.Fragments.UserInfoFragment;
import com.echoesnet.echoesshortvideo.R;

public class CUserInfoAct extends BaseActivity
{
    private UserInfoFragment userInfoFragment;
    private String focusStatus;
    private int position10;
    private int finishResult = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cuser_info);
        String uid = getIntent().getStringExtra("uId");
        String tag = getIntent().getStringExtra("Activity");
        int position = getIntent().getIntExtra("position", 0);
        userInfoFragment = UserInfoFragment.newUserInfoFrg(uid, tag, position);
        userInfoFragment.setClickListener((isFocus, position1) -> {
            Intent data = new Intent();
            focusStatus = isFocus;
            position10 = position1;
            data.putExtra("focusStatus", isFocus);
            data.putExtra("position", position1);
            setResult(finishResult, data);
            finish();
        });

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.layout, userInfoFragment);
        transaction.commit();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        if (userInfoFragment != null)
        {
            userInfoFragment.onActivityResult(requestCode, resultCode, data);
        }

    }

    @Override
    public void onBackPressed()
    {
        if (userInfoFragment!=null&&!userInfoFragment.backListener())
            finish();
        else
            finish();
    }
}
